package com.test.swaggertest.service;

import com.test.swaggertest.dao.UserMapper;
import com.test.swaggertest.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserDetailsService {
    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user=userMapper.loadUserByUsername(username);
        if(user==null){
            throw new UsernameNotFoundException("账户不存在");
        }
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
        System.out.println(user.getRoleId());
        user.setRole(userMapper.getUserRolesByRoleid(user.getRoleId()));
        System.out.println(user.getRole().getRoleId());
        return user;
    }


}
